package cn.app.edu.projectpracticeofpracticaltraining;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

public class StartActivity extends Activity {
    private int mProgress=4;
    private boolean mSkipBool=true;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start);
        final TextView mTextView = findViewById(R.id.tv_skip_activity_start);



        final Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                for (; ; ) {
                    mProgress -= 1;
                    try {
                        Thread.sleep(1000);
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                mTextView.setText(" 跳过"+mProgress+"S ");
                            }
                        });
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    if (mProgress < 2) {
                        break;
                    }
                }
                if (mSkipBool) {
                    startActivity(new Intent(StartActivity.this, MainActivity.class));
                    finish();
                }
            }
        });
        thread.start();


        mTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mSkipBool=false;
                startActivity(new Intent(StartActivity.this,MainActivity.class));
                finish();
            }
        });

    }
}